import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/components/base_refresh/base_refresh_widget.dart';
import 'package:pornhub_app/components/no_more/no_data.dart';
import 'package:pornhub_app/views/engagement/controllers/engagement_vertical_list_page_controller.dart';
import 'package:pornhub_app/views/engagement/views/engagement_list_cell.dart';

class EngagementVerticalListPage extends StatefulWidget {
  final int dataType;
  final int meetType;
  final String classifyId;
  final String cityName;

  const EngagementVerticalListPage({
    super.key,
    required this.dataType,
    required this.meetType,
    required this.classifyId,
    required this.cityName,
  });

  @override
  State createState() => _EngagementVerticalListPageState();
}

class _EngagementVerticalListPageState
    extends State<EngagementVerticalListPage> {
  @override
  void initState() {
    final cityName = widget.cityName;
    Get.lazyPut(
        () => EngagementVerticalListPageController(
              dataType: widget.dataType,
              meetType: widget.meetType,
              classifyId: widget.classifyId,
              cityName: cityName,
            ),
        tag: cityName);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final cityName = widget.cityName;
    final controller =
        Get.find<EngagementVerticalListPageController>(tag: cityName);
    return BaseRefreshWidget(
      controller,
      child: GetBuilder<EngagementVerticalListPageController>(
        id: cityName,
        tag: cityName,
        builder: (_) {
          return ListView.builder(
            itemCount:
                _.engagementList.isNotEmpty ? _.engagementList.length : 1,
            itemBuilder: (context, index) {
              if (_.engagementList.isNotEmpty) {
                return EngagementListCell(
                  data: _.engagementList[index],
                );
              } else {
                return const NoData().marginOnly(top: 200.w);
              }
            },
          );
        },
      ),
    );
  }
}
